/*
 * File     : AbstractLinuxPlatform.java
 * Created  : 16 Apr 2011
 * Revision : $Revision$
 *
 * Copyright © 2006-9 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.internal.platform;

import java.util.Set;

import com.googlecode.dni.CallingConvention;
import com.googlecode.dni.Padding;
import com.googlecode.dni.internal.library.DynamicLibrary;
import com.googlecode.dni.platform.PlatformGroup;
import com.googlecode.dni.platform.PlatformType;


/**
 * <p>
 *  Implementation of {@link Platform} for GNU/Linux.
 * </p>
 *
 * @author Matthew Wilson
 */
abstract class AbstractLinuxPlatform extends AbstractPlatform
{

    /**
     * @param platformType
     *            the platform type
     * @param defaultPadding
     *            the default padding
     * @param supportedCallingConventions
     *            the supported calling conventions
     * @param defaultCallingConvention
     *            the default calling conventions
     */
    AbstractLinuxPlatform( final PlatformType platformType,
                           final Padding defaultPadding,
                           final Set< CallingConvention > supportedCallingConventions,
                           final CallingConvention defaultCallingConvention )
    {
        super( PlatformGroup.LINUX,
               platformType,
               DynamicLibrary.open( "libdni.so", false ),
               defaultPadding,
               supportedCallingConventions,
               defaultCallingConvention );
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final String mangleLibraryName( final String name )
    {
        if ( name.contains( "/" ) || name.startsWith( "lib" ) || name.matches( ".*\\.so(\\.[0-9]+)*" ) )
        {
            return name;
        }

        return "lib" + name + ".so";
    }

}
